Is there a way to store a 10 digit number from one cell of an excel in an array using vba and using array to insert each number to each cellof table ?

Cashu

New Member
Joined
Jan 5, 2024
Messages
7
Office Version
  1. 2021
Platform
  1. Windows
VBA Code:
Dim num(9) as variant

ThisWorkbook.Worksheets("Sheet1").Range("C2").Value = num()
For j = 1 To 11
For i = 0 To 9

ActiveDocument.Tables(2).Cell(1, j + 1).Range.Text = num(i)
 Next i
Next j
Below is the excel file and the word table.Any help will be much appreciated.
1707382130291.png

1707382210569.png
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I think you are best off just using a loop to split the value up. Something along these lines:
VBA Code:
Sub test()

Dim myVal
Dim myArray(9)

' Read the value
myVal = ActiveSheet.Range("B3").Value
' Split into the array
For i = 1 To 10
    myArray(i - 1) = Mid(myVal, i, 1)
Next i
' Paste it to the columns
ActiveSheet.Range("B5:K5").Value = myArray

End Sub
 
Last edited by a moderator:
Upvote 1
Solution
ive solved this by using mid function
VBA Code:
 Dim num(0) As Variant
num(0) = ThisWorkbook.Worksheets("Sheet1").Range("C2").Value
For i = 1 To 10
ActiveDocument.Tables(2).Cell(1, i + 1).Range.Text = Mid("", i, 1)
Next i

For j = 1 To 10
ActiveDocument.Tables(2).Cell(1, j + 1).Range.Text = Mid(num(0), j, 1)
Next j
 
Upvote 0
I think you are best off just using a loop to split the value up. Something along these lines:
VBA Code:
Sub test()

Dim myVal
Dim myArray(9)

' Read the value
myVal = ActiveSheet.Range("B3").Value
' Split into the array
For i = 1 To 10
    myArray(i - 1) = Mid(myVal, i, 1)
Next i
' Paste it to the columns
ActiveSheet.Range("B5:K5").Value = myArray

End Sub

/CODE]
Thank you Nate SC.Well,I should have seen this before.I was in a hurry and didnt see the notifications list.Thank you buddy.
 
Upvote 0
ive solved this by using mid function
VBA Code:
 Dim num(0) As Variant
num(0) = ThisWorkbook.Worksheets("Sheet1").Range("C2").Value
For i = 1 To 10
ActiveDocument.Tables(2).Cell(1, i + 1).Range.Text = Mid("", i, 1)
Next i

For j = 1 To 10
ActiveDocument.Tables(2).Cell(1, j + 1).Range.Text = Mid(num(0), j, 1)
Next j
first loop to clear the existing digits or alphabets and the second loop to input the digits of the cell
 
Upvote 0
Thank you Nate SC.Well,I should have seen this before.I was in a hurry and didnt see the notifications list.Thank you buddy.
The marked solution has been changed accordingly. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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