Copy multiple first non blank cells in data with gaps

marc01

New Member
Hi all,

I have to columns of data and I am looking to copy the first non blank value and move it to the adjacent cell. The raw data looks like this:

-1
0
-1
-2
-3
-2
-1
0
1
2
3
4
3
4
5
4
3
2
1
0
1
0
1

<tbody>
</tbody>

In the first instance I would like to copy -3 in the 2nd column and paste it under the -2 in the first column.
Then copy the 2 in the first column (2nd set of rows) and paste it underneath the 1 in the first set of data in the 2nd column.
And so on (for a variable number of times)

Below I have highlighted the values in the above example:
-1
0
-1
-2
-3-3
-2
-1
0
1
22
3
4
3
4
55
4
3


<tbody>
</tbody>

<tbody>
</tbody>
Many thanks!
 

MickG

MrExcel MVP
Perhaps this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG13Dec47
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, R [COLOR="Navy"]As[/COLOR] Range
 [COLOR="Navy"]Set[/COLOR] Rng = Range("A:A").SpecialCells(xlCellTypeBlanks)
 [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] R [COLOR="Navy"]In[/COLOR] Rng.Areas
    R(1) = R(1).Offset(, 1)
    R(R.Count)(1).Offset(1, 1) = R(R.Count + 1)
[COLOR="Navy"]Next[/COLOR] R
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 

marc01

New Member
Mick that works perfectly! I have no idea what it means or how to read it :confused::( however thank you very much!

I did try to record a macro by using ctrl+down arrow to get to bottom of data set, copy the desired value, arrow left (or right depending on which column I was in - it would alternate each time), then paste.....however I didn't know how to make this loop until no values were remaining.

Again thanks for your help.

All the best.

Marc
 

Some videos you may like

This Week's Hot Topics

  • Get External Data (long shot question!)
    This is likely a long shot but I am wondering if it is at all possible for Excel to somehow 'change' the contents of a URL that is being linked to...
  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • Cell Formatting
    Good Morning, I need to format a few different cells in the following manners: A1 has to always add a colon (:) after whatever is typed in by a...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • Workbook_Change stopped working !
    I am working on an app to speed up & automate processing of Credit Cards statements. After data is input from a CSV file, it is presented to the...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
Top