Help with Do While loop formula

gllorente

New Member
Joined
Jan 15, 2019
Messages
2
Hello,

I am trying to incorporate this formula into a VBA Do while loop:

=IF(SEARCH("~*",A1),MID(A1,6,4),0)

Basically, I want to search the cells on column 1 if it contains an asterisk. If it does, I want to extract 4 numbers out of it.

It works fine when I type the formula on a cell, but I can't seem to get it to work in VBA.

Here is how I have it in VBA:

Sub get_balance()

Dim r As Integer

r = 1
Do While Cells(r, 1) <> ""
Cells(r, 3).Value = "=IF(search(""~*"",Cells(r,1),mid(Cells(r,1),6,4),0)"
r = r + 1
Loop
End Sub


Would someone please let me know what is wrong with this code? Is it even correct to use a Do While loop, or is it better to use something else? I am new at this, and trying to learn.

I would appreciate any input! Thanks very much!!!

Gretchen
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try
Code:
Cells(r, 3).FormulaR1C1 = "=IF(SEARCH(""~*"",rc[-2]),MID(rc[-2],6,4),0)"
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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