Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Conditional data move syntax

I'm not sure what I doing wrong but my posts don't seem to be received. Anyway if this message is posted, I am having trouble with this VBA Macro. The If/Then Statement appears to be formatted incorrectly as the Macro always errors on the "Then .Cells(a, "K").......half of the statement.

I am trying to copy the data from one column "K" to the "J" column if the data in K is non zero. I do not know how many rows will be in the spreadsheet. The top row contains titles, hence stop at row 2. I will also need to Bold the copied data.


Dim a As Long
With Worksheets("OUTSTANDINGSALESORDERS")
For a = .UsedRange.Rows.Count To 2 Step -1
If .Cells(a, "K").Value 0 Then .Cells(a, "K").copy .Offset(0, -1)
Next
End With

Any help is appreciated

Thanks

Jon45
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Conditional data move syntax

Try:

Dim a As Long
With Worksheets("OUTSTANDINGSALESORDERS")
For a = .UsedRange.Rows.Count To 2 Step -1
If .Cells(a, "K").Value 0 Then _
.Cells(a, "K").Copy .Cells(a, "K").Offset(0, -1)
Next
End With

or

Dim a As Long
With Worksheets("OUTSTANDINGSALESORDERS")
For a = .UsedRange.Rows.Count To 2 Step -1
With .Cells(a, "K")
If .Value 0 Then _
.Copy .Offset(0, -1)
End With
Next
End With


Regards

Trevor


"Jon45" wrote in message
...
I'm not sure what I doing wrong but my posts don't seem to be received.

Anyway if this message is posted, I am having trouble with this VBA Macro.
The If/Then Statement appears to be formatted incorrectly as the Macro
always errors on the "Then .Cells(a, "K").......half of the statement.

I am trying to copy the data from one column "K" to the "J" column if the

data in K is non zero. I do not know how many rows will be in the
spreadsheet. The top row contains titles, hence stop at row 2. I will
also need to Bold the copied data.


Dim a As Long
With Worksheets("OUTSTANDINGSALESORDERS")
For a = .UsedRange.Rows.Count To 2 Step -1
If .Cells(a, "K").Value 0 Then .Cells(a, "K").copy .Offset(0, -1)
Next
End With

Any help is appreciated

Thanks

Jon45



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Conditional data move syntax

Thanks for your help Trevor,

The first example worked great. I just started VBA programming and the syntax is difficult for me.

Thanks again

Jon45
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Conditional data move syntax

Glad to be able to help


"Jon45" wrote in message
...
Thanks for your help Trevor,

The first example worked great. I just started VBA programming and the

syntax is difficult for me.

Thanks again

Jon45



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about syntax for conditional formatting Cbeckwith Excel Worksheet Functions 6 March 23rd 10 10:06 AM
MACRO, syntax for move to different column MrDave Excel Discussion (Misc queries) 3 August 12th 09 01:46 PM
Syntax for Conditional Formats Paul Excel Worksheet Functions 2 April 15th 05 08:51 AM
can I move data from workbook A to B using a conditional formula Bonnie Excel Worksheet Functions 2 April 14th 05 09:28 PM
Syntax For Conditional Formula Dmorri254 Excel Worksheet Functions 9 November 6th 04 03:42 AM


All times are GMT +1. The time now is 12:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"