VBA error on range :

jbesclapez

Active Member
Joined
Feb 6, 2010
Messages
275
Hi guys,

I get a vba error and I do not understand why. It says error runtime 91.
It seems to be with the line
InputRngAddress = "Source!$A$1:$A$10"
I hardcoded it but it should be a range. I added the worksheet name too.

Thanks for your help


VBA Code:
   Dim InputRngAddress As Range
    Dim ReplaceRngAddress As Range
    Dim LastRowSourceA As Long
    Dim LastRowDestinationA As Long
    Dim wss As Worksheet
    Dim wsd As Worksheet
    xTitleId = "SonumByNic"
    Dim Rng As Range

    'Source XML
    Set wss = ActiveWorkbook.Sheets("Source") 'set to current worksheet name
    LastRowSourceA = wss.Cells(Rows.Count, 1).End(xlUp).Row
   ' MsgBox "Entered value is " & LastRowSourceA
   ' InputRngAddress = "Source!$A$1:$A$" & LastRowSourceA
    InputRngAddress = "Source!$A$1:$A$10"
   
    'MsgBox "Entered value is " & InputRngAddress
    'Destination XML
    Set wsd = ActiveWorkbook.Sheets("Replace") 'set to current worksheet name
    LastRowDestinationA = wsd.Cells(Rows.Count, 1).End(xlUp).Row
    ReplaceRngAddress = "Replace!$A$1:$B$" & LastRowDestinationA
   
   ' MsgBox "Entered value is " & ReplaceRngAddress
   
    Application.ScreenUpdating = False
    For Each Rng In ReplaceRngAddress.Columns(1).Cells
        InputRngAddress.Replace what:=Rng.Value, replacement:=Rng.Offset(0, 1).Value
    Next
    Application.ScreenUpdating = True
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
That is a String, not a Range object. You need:

Code:
Set Inputrngaddress = Sheets("Source").range("A1:A10")

though that makes your variable name extremely confusing!
 
Upvote 0
Solution
InputRngAddress = "Source!$A$1:$A$10"
Anything enclosed in double-quotes is treated as literal text.
You need to use Range... when setting ranges, and neeed to use the Set command.
You also need to use the Sheet reference, i.e.
VBA Code:
Set InputRngAddress = Sheets("Source").Range("A1:A10")
 
Upvote 0
You are welcome.
Glad we were able to help!
 
Upvote 0

Forum statistics

Threads
1,214,412
Messages
6,119,365
Members
448,888
Latest member
Arle8907

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