VBA to fill values to next column

nburaq

Board Regular
Joined
Apr 2, 2021
Messages
220
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi Gents,
I need VBA code (I don't know how to do it with formula) to convert the values screenshot 1 to screenshot 2. I am dealing generally this kind of data sheets sometimes a combination of letters and numbers so if it could be a general solution It can be so nice! Thanks for help and comments!
1_.png
2_.png
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
with formula I have a trick ;
Excel Formula:
IF(ISBKANK(A2);"";IF(A2>100;"";A2))
However then I have to write similar IF formula to distribute the values to another columns and then I have to delete original column to convert situation1 to 2
 
Upvote 0
How about
VBA Code:
Sub nburaq()
   Dim Rng As Range
   Dim r As Long
   
   For Each Rng In Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
      For r = 2 To Rng.Count Step 2
         Rng(r).Offset(-1, 1).Value = Rng(r).Value
         Rng(r).ClearContents
      Next r
   Next Rng
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub nburaq()
   Dim Rng As Range
   Dim r As Long
  
   For Each Rng In Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
      For r = 2 To Rng.Count Step 2
         Rng(r).Offset(-1, 1).Value = Rng(r).Value
         Rng(r).ClearContents
      Next r
   Next Rng
End Sub
it is called magic :) !!! Thanks a lot! I assume Offset (-1,1) writes the values a row above and a next column, and step 2 is since they cell values are next to each other right? Nice... Any link where can I learn VBA programming for Excel only?
 
Upvote 0
You're welcome & thanks for the feedback.
There are plenty of sites on the net that deal with Excel VBA.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,748
Members
448,989
Latest member
mariah3

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