I am trying to write a macro that will copy data from on location to another if the value in a particular cell is greater than -0-. Below is my attempt which isn't working. Any help would be greatly appreciated.
MBInDe
Sub testz()
'
' testz Macro
' Macro recorded 10/20/2009 by MBInDe
'
' Keyboard Shortcut: Ctrl+z
'
If Cell("A33") = >0 Then
Range("G6:G13").Select
Selection.Copy
Range("C6").Select
ActiveSheet.Paste
End If
End Sub
Fix1
--------------------------
Are you trying to copy the value in Cell A33 to Cells G6 thru G13?
OR
Are you trying to copy the value of Cell A33 to Cell G6, Cell A34 to Cell G7, etc.?
-------------------------
Fix2
----------------------------
ou do not really need any code to perform this operation. You can use a formula.
For Example, enter the following formula into Cell C6
Then drag the formula down to Cell C13.
Place the white cross on the lower right-hand corner of C6 (it should turn into a black cross), click and hold the left-button on the mouse and drag down to C13. Then release the button.
If you really want to use code to perform this operation let me know and I will help you do so.
----------------------------
Fix 3
Sounds like a plan. My next question is when do you want the code to run?
1. Manually run the code (via, command button, etc.)
2. The code runs when the workbook is opened (that is the only time the code will run. So, if the number in A33 changes while the workbook is opened, the code will not run)
3. When the value in A33 changes
4. Some other trigger
Here is the code that should work...
Once you let me know how you want it to run, I can help you set it up that way (options above).
Fix 4
-------------------
Will this code be ran once while the workbook is opened, or multiple times? If multiple times, what do you want to happen if the value in A33 falls to 0? Are the numbers in Cells C6 thru C13 going to remain the same, become blank, etc.?
What exactly do you need help with? Do you know how to place a command button on the worksheet?
------------------
Fix5
---------------------------------
I do not see the command button within the Excel workbook. Place the command button on the sheet you want it to go, and then re-attach the workbook.
Also, let us know exactly where you want the values to be copied from and where to paste them. Let us know what happens if the value is equal or less than 0.
Give us as much details as you can. Let us know exactly what you need us to help you with.
---------------------------------------------------------
MBInDe
Sub testz()
'
' testz Macro
' Macro recorded 10/20/2009 by MBInDe
'
' Keyboard Shortcut: Ctrl+z
'
If Cell("A33") = >0 Then
Range("G6:G13").Select
Selection.Copy
Range("C6").Select
ActiveSheet.Paste
End If
End Sub
Fix1
--------------------------
Are you trying to copy the value in Cell A33 to Cells G6 thru G13?
OR
Are you trying to copy the value of Cell A33 to Cell G6, Cell A34 to Cell G7, etc.?
-------------------------
Fix2
----------------------------
ou do not really need any code to perform this operation. You can use a formula.
For Example, enter the following formula into Cell C6
Code:
=IF($A$33>0,G6,"")
Place the white cross on the lower right-hand corner of C6 (it should turn into a black cross), click and hold the left-button on the mouse and drag down to C13. Then release the button.
If you really want to use code to perform this operation let me know and I will help you do so.
----------------------------
Fix 3
Sounds like a plan. My next question is when do you want the code to run?
1. Manually run the code (via, command button, etc.)
2. The code runs when the workbook is opened (that is the only time the code will run. So, if the number in A33 changes while the workbook is opened, the code will not run)
3. When the value in A33 changes
4. Some other trigger
Here is the code that should work...
Code:
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
If ws.Range("A33") > 0 Then
ws.Range("G6:G13").Copy
ws.Range("C6").PasteSpecial Paste:=xlPasteAll
Application.CutCopyMode = False
End If
Fix 4
-------------------
Will this code be ran once while the workbook is opened, or multiple times? If multiple times, what do you want to happen if the value in A33 falls to 0? Are the numbers in Cells C6 thru C13 going to remain the same, become blank, etc.?
What exactly do you need help with? Do you know how to place a command button on the worksheet?
------------------
Fix5
---------------------------------
I do not see the command button within the Excel workbook. Place the command button on the sheet you want it to go, and then re-attach the workbook.
Also, let us know exactly where you want the values to be copied from and where to paste them. Let us know what happens if the value is equal or less than 0.
Give us as much details as you can. Let us know exactly what you need us to help you with.
---------------------------------------------------------
Hiç yorum yok:
Yorum Gönder