Can't get RIGHT to work

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
271
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have the following (probably very inefficient bit of code) which is failing with "Object Required". Can anyone tell me what I'm doing wrong and perhaps suggest a better way rather than using a FOR-NEXT loop on 32,000 records?

Code:
lrow = wb1.Sheets("Go Card").Cells(wb1.Sheets("Go Card").Rows.Count, "B").End(xlUp).Row
For a = 2 To lrow
b = Right(wb1.Sheets("Go Card").Range("AE" & a), 13).Value
Range("A" & a).Value = b
Next

b is dimmed as a String.

If I take the right out and just use
Code:
b = wb1.Sheets("Go Card").Range("AE" & a).Value

it runs fine (albeit slowly)

Many thanks as always.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You've got the Value in the wrong place:

Code:
b = Right(wb1.Sheets("Go Card").Range("AE" & a).Value, 13)
 
Upvote 0
You could simply use a formula then replace it:

Code:
lrow = wb1.Sheets("Go Card").Cells(wb1.Sheets("Go Card").Rows.Count, "B").End(xlUp).Row

with Range("A2:A" & lrow)
.Formula = "=RIGHT(AE2,13)"
.Value = .value
end with
 
Upvote 1
Solution
Are you trying to reverse the order?
 
Upvote 0
You could simply use a formula then replace it:

Code:
lrow = wb1.Sheets("Go Card").Cells(wb1.Sheets("Go Card").Rows.Count, "B").End(xlUp).Row

with Range("A2:A" & lrow)
.Formula = "=RIGHT(AE2,13)"
.Value = .value
end with
Perfect, works a treat, many thanks!
 
Upvote 0

Forum statistics

Threads
1,215,741
Messages
6,126,587
Members
449,319
Latest member
iaincmac

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