Moving Cells

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to move a range of cells to another starting point? i.e. Lets say I have a row (1) consisting of 10 cells each of which could have any numeric value from 0 up. Cells A1 and B1 each have a value of 0 whilst C1 to J1 have values of >0. What I want to do is identify C1 has the first in the range having a value of >0 and to move it and the rest of the cells (D1 to J1) 2 cells to the left so that cells C1 to J1 are now A1 to H1
I'm told this is possible but I don't know how to do it.
 
Yes this is possible ...

I don't have time to write the code, but here is part of a
macro that copies a variable range from one
sheet "srcsht." to another sheet "destsht."

Dim DataCol As Integer ' First column of data
Dim ncol As Integer ' Number of Columns in the
Populated Area
Dim nrow As Integer ' Number of Rows in the Populated
Area
Dim i As Integer ' Miscellaneous Local Index
Dim j As Integer ' Miscellaneous Local Index
Dim id As Integer ' Integer District value
Dim srcsht As Worksheet ' Active Sheet to process in the
Source Workfile
Dim destsht As Worksheet ' Single worksheet object that
becomes the destination file

' Find the Populated Area of the spread sheet in columns
and rows
ncol = ActiveSheet.UsedRange.Columns.Count
nrow = ActiveSheet.UsedRange.Rows.Count

' Here is the most important part of what you want ...
' Block Copy from one range to another range.
' The destination range can be as simple as Range("A1")

' Copy Columns to the new sheet
srcsht.Range(srcsht.Cells(1, i), srcsht.Cells(nrow,
i)).Copy _
Destination:=destsht.Range(destsht.Cells(1, j),
destsht.Cells(nrow, j))

-----Original Message-----
Is it possible to move a range of cells to another
starting point? i.e. Lets say I have a row (1)
consisting of 10 cells each of which could have any
numeric value from 0 up. Cells A1 and B1 each have a
value of 0 whilst C1 to J1 have values of >0. What I want
to do is identify C1 has the first in the range having a
value of >0 and to move it and the rest of the cells (D1
to J1) 2 cells to the left so that cells C1 to J1 are now
A1 to H1
 
Thanks Art .... afraid I'm a bit sketchy on VisualBasic. Tried it but wasn't sure about 'Dim i', 'Dim j' and 'Dim id'. When I ran it I got a 'run time error 91' message saying 'Object variable or With block variable not set'.

Any further help would be appreciated.

Thanks
 
Back
Top