Writing large ranges to multiple cells

krshnn

New Member
Joined
Mar 23, 2022
Messages
17
Office Version
  1. 2013
Platform
  1. Windows
I need an alternative to below way of writing codes
Range("A1").value = "S.No"
Range("B1").value = "Bill No"
Range("c1").value = "Shipping bill no"
Range("D1").value = "code"
Range("E1").value = "Processing partner"
Range("f1").value = "FOB value"
and so on till Range("Z1").

At times, my requirement might be in A1.value to A20.value sort of fashion (i.e., vertical manner rather than horizontal manner)

So basically the question is there an easier an way to write the above lines of code without including range/cell address each time.
I'm okay with entering contiguous cell range once.
Request you to provide answer for both multiple vertical range.value and horizontal range.value scenarios.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try something like this:
One for Horizontal in row 1
Modify array values
VBA Code:
Sub Using_Arrray_Horizonal()
'Modified 11/1/2022  1:12:11 PM  EST
Application.ScreenUpdating = False
Dim i As Long
Dim Del As Variant
Dim s As Long
Del = Array("Alpha", "Bravo", "Charlie", "Delta", "Echo")
s = UBound(Del)

For i = 0 To s
    Cells(1, i + 1).Value = Del(i)
Next
Application.ScreenUpdating = True

End Sub
One for Vertical in Column 1
Modify array values:
VBA Code:
Sub Using_Arrray_Vertical()
'Modified 11/1/2022  1:12:11 PM  EST
Application.ScreenUpdating = False
Dim i As Long
Dim Del As Variant
Dim s As Long
Del = Array("Alpha", "Bravo", "Charlie", "Delta", "Echo")
s = UBound(Del)

For i = 0 To s
    Cells(i + 1, 1).Value = Del(i)
Next
Application.ScreenUpdating = False

End Sub
 
Upvote 0
Try this For Row(1)
VBA Code:
Sub Using_Arrray_Horizonal()
'Modified 11/1/2022  1:12:11 PM  EST
Application.ScreenUpdating = False
Dim i As Long
Dim Del As Variant
Dim s As Long
Del = Array("Alpha", "Bravo", "Charlie", "Delta", "Echo")
s = UBound(Del)

For i = 0 To s
    Cells(1, i + 1).Value = Del(i)
Next
Application.ScreenUpdating = True
MsgBox "Horizontal"

End Sub

Try this for column 1
VBA Code:
Sub Using_Arrray_Vertical()
'Modified 11/1/2022  1:12:11 PM  EST
Application.ScreenUpdating = False
Dim i As Long
Dim Del As Variant
Dim s As Long
Del = Array("Alpha", "Bravo", "Charlie", "Delta", "Echo")
s = UBound(Del)

For i = 0 To s
    Cells(i + 1, 1).Value = Del(i)
Next
Application.ScreenUpdating = True
MsgBox "Vertical"
End Sub
 
Upvote 0
Another option is
For horizontal
VBA Code:
Sub krshnn()
   Dim Ary As Variant
   
   Ary = Array("S.No", "Bill No", "Shipping bill no", "code", "Processing partner", "FOB value")
   Range("A1").Resize(, UBound(Ary) + 1).Value = Ary
End Sub
and Vertical
VBA Code:
Sub krshnn()
   Dim Ary As Variant
   
   Ary = Array("S.No", "Bill No", "Shipping bill no", "code", "Processing partner", "FOB value")
   Range("A1").Resize(UBound(Ary) + 1).Value = Application.Transpose(Ary)
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,047
Messages
6,122,858
Members
449,096
Latest member
Erald

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