One formula activated by where you are

daniels012

Well-known Member
Joined
Jan 13, 2005
Messages
5,219
I copy and paste data from Estimating(sheet) to WhatToOrder(sheet).
I set up a button to do this action as I wish. I have 7 buttons. Do I need to re-write the code 6 more times or can I execute the code based upon where I am on the sheet?

Code:
Sub JobData1()
'
' JobData1 Macro
' Enter Data from Estimating to the job one column
'

'
    Application.ScreenUpdating = False
    Range("E2").Select
    Sheets("ESTIMATING").Select
    Range("B3").Select
    Selection.Copy
    Sheets("What to Order").Select
    Range("E2").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    Application.CutCopyMode = False
    Sheets("ESTIMATING").Select
    Range("B8").Select
    Selection.Copy
    Sheets("What to Order").Select
    Range("E3").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    Sheets("ESTIMATING").Select
    Range("H3:H27").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("What to Order").Select
    Range("E4").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    Application.CutCopyMode = False
    Selection.NumberFormat = "0.00"
    Range("E2").Select
    Application.ScreenUpdating = True
End Sub

Works great! I know I can copy and paste each sets of code, change all the numbers but it would be a lot easier to have it copy from Estimating and paste on current cell, then down 1 place, then down 1 more cell, etc. etc.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Like this?

Code:
Sub JobData1()

' JobData1 Macro
' Enter Data from Estimating to the job one column

    Application.ScreenUpdating = False
    Sheets("ESTIMATING").Activate
    Range("B3").Copy
    Sheets("What to Order").Activate
    ActiveCell.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(1, 0).Select
    Sheets("ESTIMATING").Activate
    Range("B8").Copy
    Sheets("What to Order").Activate
    ActiveCell.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(1, 0).Select
    Sheets("ESTIMATING").Activate
    Range("H3:H27").Copy
    Sheets("What to Order").Activate
    With ActiveCell
        .PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
        .NumberFormat = "0.00"
    End With
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub

Or does the range in "Estimating" need to be dynamic also?
 
Upvote 0
THAT IS PERFECT!!!

Thank You, That is so much easier. Now when I add a row of new data it will be much easier also. I just have to add a set of code and offset(1,0)

Thanks again,
Michael
 
Upvote 0
By the way,
Is there an easier way to combine all the cells to copy. Then paste all in a row on the next sheet. It seems there would be a lot less code written that way?


New to this coding stuff... But I LOVE IT!

Michael :pray:
 
Upvote 0
if they are all in the same column /row you can do it, but I you are copying stuff that is all over the place and trying to copy to a single column I think you will end up with more code. Or at least code that above my skill level.

you can combine consistant rows/columns (like B1 nd B8) like this, but I dont know how to also include your H range in there too and be able to paste to a single column.

Code:
Sub JobData1()

'JobData1 Macro
' Enter Data from Estimating to the job one column

    Application.ScreenUpdating = False
    Sheets("ESTIMATING").Activate
    Range("B3,B8").Copy
    Sheets("What to Order").Activate
    ActiveCell.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    ActiveCell.Offset(1, 0).Select
    Sheets("ESTIMATING").Activate
    Range("H3:H27").Copy
    Sheets("What to Order").Activate
    With ActiveCell
        .PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
        .NumberFormat = "0.00"
    End With
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,206,713
Messages
6,074,483
Members
446,071
Latest member
gaborfreeman

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