Macro to replace ? with the actual row number

Chmeee

New Member
Joined
Feb 14, 2005
Messages
3
Hi, I am hoping someone can help me with this
Each week I use a macro to open a Sales spreadsheet that was exported from MSaccess and copy it to my report
However, the freight formula in each row of the spreadsheet is incorrect as it does not show the row numbers
The formula shows as =ROUND(k?*0.01560, 2). Where the “?” should be the row number. Column K contains the various Qtys and the .01560 is the cents per litre.
Is there any way to have the macro change this to the relevant row numbers without having to go down the column selecting each row?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
17,100
Office Version
  1. 365
  2. 2016
  3. 2010
Platform
  1. Windows
Assuming the formulas are in the Range ("A2:A20") maybe something like

Try it on a copy of your workbook

Code:
Dim rCell As Range

For Each rCell In Range("A2:A20")
    rCell.Formula = Replace(rCell.Formula, "K?", "K" & rCell.Row, compare:=vbTextCompare)
Next rCell

M.
 
Upvote 0

Chmeee

New Member
Joined
Feb 14, 2005
Messages
3
Thanks Marcelo, Works perfectly
It was that quick it was finished before I looked back up from my watch
Will save me lots of time
Thanks again
 
Upvote 0

Marcelo Branco

MrExcel MVP
Joined
Aug 23, 2010
Messages
17,100
Office Version
  1. 365
  2. 2016
  3. 2010
Platform
  1. Windows
Thanks Marcelo, Works perfectly
It was that quick it was finished before I looked back up from my watch
Will save me lots of time
Thanks again

You are welcome and thanks for the feedback

M.
 
Upvote 0

Forum statistics

Threads
1,191,178
Messages
5,985,142
Members
439,942
Latest member
bkexcel11230

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
Top