Restructure old code

rhino4eva

Active Member
Joined
Apr 1, 2009
Messages
262
Office Version
  1. 2010
Platform
  1. Windows
So i have been using a vba code to fill an 12 columnsX 8 rows into columns of 8 form a list of 96 of one column
i need to modify the code to fill the the same 12 column x 8 Rows but now i need to fill horizontally into rows of 12
and each number will require 2 wells
eg
1
2
3
to become 1 1 2 2 3 3

the code is this

Sub RUNFILL()
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim rFound As Range
Set WS1 = Sheets("DATA")
Set WS2 = Sheets("BackingSheet")
For X = 3 To 99
With WS2.Range("c22:f45")
On Error Resume Next
target = WS1.Range("b" & X).Value
On Error Resume Next
Set rFound = .Find("*", SearchDirection=xlPrevious,SearchOrder=xl,ByColumns,L ookIn:xlValues)

On Error Goto 0
If InStr(target, "Probationary") <> sBPPdetect Then
ElseIf rFound Is Nothing Then
.Cells(1).Value = target
ElseIf Intersect(rFound, .Cells(.Rows.Count, .Columns.Count)) Is Nothing Then
If rFound.Row < .Rows(.Rows.Count).Row Then
rFound.Offset(1, 0).Value = target
Else
rFound.Offset(-.Rows.Count + 1, 1).Value = target
End If
End If
End With
Next X
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
To get a better response try posting data using Mr Excel's excellent XL2BB add-in. See XL2BB - Excel Range to BBCode

If possible post a link to your workbook. Put it on Dropbox, Box, 1Drive, etc. then use the link icon above the message area. If necessary put fake but realistic data in the workbook.
 
Upvote 0
grid.xls
ABCDEFGHIJKLMNOP
1number123456789101112
21a191725
32b2101826
43current codec3111927
54d4122028
65e5132129
76f6142230
87g71523
98h81624
109
1110single vertical mover form a colum to 8 x12 grid
1211
1312
1413
1514
1615new code123456789101112
1716a112233445566
1817b778899101011111212
1918c131314141515161617171818
2019d191920202121222223232424
2120e252526262727282829293030
2221f6142230
2322g71523
2423h81624
2524
2625duplicate numbers from column a to 12x8 grid
2726
2827
2928
3029
3130
Sheet1
 
Upvote 0
Sub currentRUNFILL()

Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim rFound As Range

Set WS1 = Sheets("Sheet1")
Set WS2 = Sheets("Sheet1")
Sheets("Sheet1").Range("e2:n9").ClearContents
For X = 2 To 97

With WS2.Range("e2:n9")
On Error Resume Next
target = WS1.Range("a" & X).Value
On Error Resume Next
Set rFound = .Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns, LookIn:=xlValues)
On Error GoTo 0
If rFound Is Nothing Then
.Cells(1).Value = target
ElseIf Intersect(rFound, .Cells(.Rows.Count, .Columns.Count)) Is Nothing Then
If rFound.Row < .Rows(.Rows.Count).Row Then
rFound.Offset(1, 0).Value = target
Else
rFound.Offset(-.Rows.Count + 1, 1).Value = target
End If
End If

End With


Next X

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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