Advice on macro formula

Andyb2

New Member
Joined
Jan 24, 2021
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I want to run a macro that does the following every time I open a salary sheet:

1. If column N displays the code 2102, 2111, 2112, 2201, 2101, 2301, 2312 then copy the name displayed in column H and paste this to Column AL.
2. If column N displays the code 2102, 2111, 2112, 2201, 2101, 2301, 2312 then copy the text displayed in column F to column AM.

However, I'm not sure what type of formula I should use If Statement, Vlookup?

thanks,

Andy
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi,
I need help to develop a VBA Stack up Formula on excel with some peculiarities.
for each "stack up" I need to repeat the data from column A until U which carries noun numeric data and stack up the data starting from column V until AG which carries numerical data from Jan to Dec (12 columns) Also, I need to do it by carrying the format of the cells, colors....
There is anyone that can help me with this VBI?
Regards

Rodrigo
 
Upvote 0
@Andyb2, I'm not clear why you need a macro?

Would this formula in AL2 meet your first requirement?

AL2: =IF(ISNUMBER(MATCH(N2,{2102,2111,2112,2201,2101,2301,2312},)),H2,"")

(I'm assuming you mean N contains 2012 or 2111 or 2112 or .... ?)
 
Upvote 0
Hi Stephen,

With the formula I would have to paste this into a spreadsheet each time and filter and I want to have around 10 condition, so the 400 numbers would be office supplies for example and 500 numbers would be travel. Thats why I would like to use a formula.

I tried pasting your formula into the spreadsheet in column AL but nothing happens
 
Upvote 0
I've used this code, which works for 2101, however when I add Or and the other numbers 2111 etc. I get the error message 'Block if without end if'?


VBA Code:
Sub Cheesey()
    For Each r In Intersect(ActiveSheet.UsedRange, Range("A:A"))
        If r.Text = "2101" Or "2111" Or "2112" Or "2201" Or "2301" Or "2312" Then
            r.Offset(0, 1) = "Salary"  

            Else
            
        If r.Text = "3201" Or "3202" Or "3203" Or "3028" Or "3010" Then
            r.Offset(0, 1) = "Consumables"
             End If
    Next r
End Sub
 

Attachments

  • 1612013487711.png
    1612013487711.png
    50 KB · Views: 3
Upvote 0
How about
VBA Code:
Sub Cheesey()
   For Each r In Intersect(ActiveSheet.UsedRange, Range("A:A"))
      Select Case r.Text
         Case "2101", "2111", "2112", "2201", "2301", "2312"
            r.Offset(0, 1) = "Salary"
         Case "3201", "3202", "3203", "3028", "3010"
            r.Offset(0, 1) = "Consumables"
      End Select
   Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,877
Messages
6,122,051
Members
449,064
Latest member
scottdog129

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