Understanding VBA Macro

PresidentEvil

New Member
Joined
Jan 2, 2021
Messages
34
Office Version
  1. 2021
  2. 2016
Platform
  1. Windows
Hi,

I have a macro created by one of my former colleagues. It a bit complex macro with multiple steps which includes application of mutiple formula. He is no longer working for us, and we have decided to move to power automate with Office scripts. I have been decoding each step and converting them into office script however one such step is very difficult to understand (at least for me). Any help on this will be highly appreciated.

Below is a part of macro that he designed. Not able to understand what's going on in this...any explanation step by step would be really helpful

VBA Code:
Sub test()
Range("J4:M4").Select 'Range J4 to M4 has formula
Range(Selection, Selection.End(xlDown)).Select
Range("Z2") = Selection.Row + Selection.Rows.Count - 1
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    'Selection.Replace What:="Check", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
      Selection.Replace What:="Check", Replacement:="", LookAt:=xlWhole, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    'Selection.SpecialCells(xlCellTypeBlanks).Select
    Application.CutCopyMode = False
    'Selection.FormulaR1C1 = "=R[1]C"
    
    Range(Range("Z3")).Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.FormulaR1C1 = _
            "=IF(ISNA(MATCH(CONCATENATE(C[-9],""Text""),C[4],0)),"""",R[1]C)"

 'mutiple formulas like the above
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
It replaces all the formulas in columns J:M with static values, then clears any cells that contain just the word "Check". Then it populates any blank cells in the range specified in Z3 with that MATCH formula.
 
Upvote 0
Solution
Hi,

Maybe if you Step Through it (using F8) a line at a time, it will make sense for you.

Then you can see what you want to do with your new script.

cheers
Rob
 
Upvote 0
It replaces all the formulas in columns J:M with static values, then clears any cells that contain just the word "Check". Then it populates any blank cells in the range specified in Z3 with that MATCH formula.
Thanks, I was confused with the last part. If it's not too much of an ask, can you please help me in converting the formula. I mean what it means by C[-09], Is it column A? Break it down for me please... -

VBA Code:
"=IF(ISNA(MATCH(CONCATENATE(C[-9],""Text""),C[4],0)),"""",R[1]C)"
 
Upvote 0
Hi,

Maybe if you Step Through it (using F8) a line at a time, it will make sense for you.

Then you can see what you want to do with your new script.

cheers
Rob
I did try that, that's how I converted half of it into office script. However, this one seemed more complex than I thought it would be. The entire code is a mess, the creator of this macro did make sure to make it very confusing for anyone breaking it in future. Don't know why.
 
Upvote 0
Thanks, I was confused with the last part. If it's not too much of an ask, can you please help me in converting the formula. I mean what it means by C[-09], Is it column A? Break it down for me please... -

VBA Code:
"=IF(ISNA(MATCH(CONCATENATE(C[-9],""Text""),C[4],0)),"""",R[1]C)"
C[-9] means the column 9 to the left of the one with the formula in it. C[4] means the column 4 to the right.
 
Upvote 1

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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