Public Range

Eziooh

New Member
Joined
Apr 1, 2019
Messages
17
Hello, I think it is a noob question but...

How can I range a cell with a variable to a module?
My code right now is pretty simple, this is on the actual sheet:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)    If Target.Address = "$D$7" Then
        Call Procurar
    End If
End Sub

And in the module code I want to use a variable which ranges the target address...
Is it possible? If it is, how?
Thanks for the time!
 
In that case
Code:
valor = rng.Value ' This gives the value of the cell, assuming that only one cell was changed
valor = rng.Address ' This gives the address
 
Last edited:
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Thank you, now I am trying to get this to work, when I am done or with any question, I will post here, seems okay to you?
 
Upvote 0
It's me again, I think I have something wrong, the macro doesn't run...


(Module)
Code:
Sub Procurar(rng As Range)

Dim lastrow As Long
Dim Cell, cRange, a As Range
Dim valor, resultado As String
valor = rng.Value
lastrow = Sheets("Finalsheet").Cells(Rows.Count, 4).End(xlUp).Offset(1).Row
a = rng.Address
' Range to search
    Set cRange = Worksheets("Sheet1").Range("A1:B1000")
' for each cell in range
        For Each Cell In cRange
' if cell has the value
            If Cell.Value = valor Then
' then the valor appears
              resultado = Cell.Offset(0, -1).Value
            
            Select Case a
            Case a = Worksheets("sheet2").Range("D7") : Sheets("Finalsheet").Cells(lastrow, 4) = resultado
            End Select
End If
' Check next cell in range
        Next Cell


End Sub

(In sheet2, I have a drop-down which I need...)
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "D7" Then
        Call Procurar(Target)
    End If
End Sub
 
Last edited:
Upvote 0
What are you trying to do on this line?
Code:
Case a = Worksheets("sheet2").Range("D7") = Sheets("Finalsheet").Cells(lastrow, 4) = resultado
 
Upvote 0
What are you trying to do on this line?
Code:
Case a = Worksheets("sheet2").Range("D7") = Sheets("Finalsheet").Cells(lastrow, 4) = resultado
Trying to paste the "resultado"
I don't know if it works as it is, I am new to vba...
 
Last edited:
Upvote 0
Glad you sorted it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top