SUSAN BAXTER
New Member
- Joined
- Apr 1, 2019
- Messages
- 47
Hi
I have code that I would like to make a small change to but need some help with. I only need the first cell in all the ranges in all the “arr1” in my code below to be increased by one row , so the 1st change is the current range is Range("D22:I36") change to Range("E22:I36"). I can do this on my own but I’m having trouble with the changes needed in the offsets (believe that’s the correct terminology) in the code. There is a lot going on in that code and I’m no expert like you are.
No changes are needed in arr2.
Thanks so much for any help.
I have code that I would like to make a small change to but need some help with. I only need the first cell in all the ranges in all the “arr1” in my code below to be increased by one row , so the 1st change is the current range is Range("D22:I36") change to Range("E22:I36"). I can do this on my own but I’m having trouble with the changes needed in the offsets (believe that’s the correct terminology) in the code. There is a lot going on in that code and I’m no expert like you are.
No changes are needed in arr2.
Thanks so much for any help.
Code:
Sub PlaceNumbers()
Dim c As Range, rng1 As Range, rng2 As Range, rng3 As Range, rng4 As Range
Dim last1 As Long, last2 As Long, rtar As Long, xtar As Long
Application.ScreenUpdating = False
With ActiveSheet
'create arrays
arr1 = Array(.Range("D22:I36"), .Range("J22:O36"), .Range("P22:U36"), .Range("V22:AA36"), .Range("AB22:AG36") _
, .Range("AH22:AM36"), .Range("AN22:AS36"), .Range("AT22:AY36"), .Range("AZ22:BE36"), .Range("BF22:BK36"))
arr2 = Array(.Range("BN22:BQ36"), .Range("BR22:BU36"), .Range("BV22:BY36"), .Range("BZ22:CC36"), .Range("CD22:CG36") _
, .Range("CH22:CK36"), .Range("CL22:CO36"), .Range("CP22:CS36"), .Range("CT22:CW36"), .Range("CY22:DA36")) '
'loop through arrays
For i = LBound(arr1) To UBound(arr1)
Set rng1 = arr1(i)
Set rng3 = arr2(i) '
last1 = .Cells(.Rows.Count, ColLetter(rng1.Columns(1).Column)).End(xlUp).Row
last2 = .Cells(.Rows.Count, ColLetter(rng3.Columns(1).Column)).End(xlUp).Row
For Each c In rng1.Offset(1, 2).Resize(, 1)
If c <> "" Then
rtar = Evaluate("=MATCH(" & ColLetter(rng1.Columns(2).Column) & rng1.Row & "&" & ColLetter(rng1.Columns(3).Column) & rng1.Row & "," & ColLetter(rng3.Columns(1).Column) & "1:" & ColLetter(rng3.Columns(1).Column) & last2 & "&" & ColLetter(rng3.Columns(3).Column) & "1:" & ColLetter(rng3.Columns(3).Column) & last2 & ",0)")
xtar = Application.Match(c.Offset(0, -2), Range(ColLetter(rng3.Columns(1).Column) & rtar & ":" & ColLetter(rng3.Columns(1).Column) & last2), 0)
With Application.WorksheetFunction
c.Offset(0, 1) = .Index(Range(ColLetter(rng3.Columns(2).Column) & rtar & ":" & ColLetter(rng3.Columns(2).Column) & last2), xtar)
c.Offset(0, 2) = .Index(Range(ColLetter(rng3.Columns(3).Column) & rtar & ":" & ColLetter(rng3.Columns(3).Column) & last2), xtar)
c.Offset(0, 3) = .Index(Range(ColLetter(rng3.Columns(4).Column) & rtar & ":" & ColLetter(rng3.Columns(4).Column) & last2), xtar)
End With
End If
Next c
Next
End With
Application.ScreenUpdating = True
End Sub
Function ColLetter(Collet As Integer) As String
ColLetter = Split(Cells(1, Collet).Address, "$")(1)
End Function
[SIZE=3]<style type="text/css">pre { direction: ltr; color: rgb(0, 0, 0); text-align: left; }pre.western { font-family: "Liberation Mono", serif; }pre.cjk { font-family: "WenQuanYi Micro Hei Mono"; }pre.ctl { font-family: "Liberation Mono"; }p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 0); line-height: 115%; text-align: left; }p.western { font-family: "Liberation Serif", serif; font-size: 12pt; }p.cjk { font-family: "WenQuanYi Micro Hei"; font-size: 12pt; }p.ctl { font-family: "Lohit Devanagari"; font-size: 12pt; }a:link { }</style>
[/SIZE]
<style type="text/css">p { margin-bottom: 0.25cm; direction: ltr; color: rgb(0, 0, 0); line-height: 115%; text-align: left; }p.western { font-family: "Liberation Serif", serif; font-size: 12pt; }p.cjk { font-family: "WenQuanYi Micro Hei"; font-size: 12pt; }p.ctl { font-family: "Lohit Devanagari"; font-size: 12pt; }a:link { }</style>