user3093908
user3093908

Reputation: 13

With VBA in Excel how can I reference a cell with a variable

As the title suggests, I can't figure out how to go to a cell using a variable for the row. I have attached the code I currently have and the commented section is what I'm having issues with, Thanks!

Private Sub Go_Click()
Dim id As Double
Dim qt As Double
Dim num As Double
Dim rngSearch As Range, rngFound As Range
id = Range("D4").Value
qt = Range("E4").Value
Set rngSearch = Range("A:A")
Set rngFound = rngSearch.Find(What:=id, LookIn:=xlValues, LookAt:=xlPart)
num = rngFound.Row
If rngFound Is Nothing Then
MsgBox "Stock ID Not Found"
Else
MsgBox rngFound.Row
'Range("O num.Value") = Range("O num.Value") - qt
End If
Range(rngFound.Row) = Range(rngFound.Row) - qt
End Sub

Upvotes: 0

Views: 184

Answers (1)

findwindow
findwindow

Reputation: 3153

Perhaps

Range("O" & num).value=Range("O" & num).value-qt

Upvotes: 1

Related Questions