PDA

View Full Version : about Array



idnoidno
04-16-2017, 11:28 PM
 
100
20
10


 
100
20
10


A
1
12
 


A
1
12
10


B
 
 
5


B
100
20
5


C
 
15
 


C
100
15
10


D
50
 
 


D
50
20
10





I would like to use EXCEL VBA ARRAY way, let the blank form on the left side of the table to fill in the top of the value, into the right form, if someone can help, I will be very grateful.

YasserKhalil
04-17-2017, 12:11 AM
Try this code

Sub Test() Dim arr As Variant
Dim i As Long
Dim j As Long

arr = Range("A1").CurrentRegion.Value

For i = 2 To UBound(arr, 1)
For j = 2 To UBound(arr, 2)
If arr(i, j) = "" Then
arr(i, j) = arr(1, j)
End If
Next j
Next i

Range("G1").Resize(UBound(arr, 1), UBound(arr, 2)).Value = arr
End Sub

YasserKhalil
04-17-2017, 12:14 AM
Cross-Post at this link
http://chandoo.org/forum/threads/how-to-copy-fixed-values-into-the-blank-cells.34048/

idnoidno
04-17-2017, 12:18 AM
Thank you very much for your reply, I will study it carefully.
If there is a problem, can I ask you?

idnoidno
04-17-2017, 12:26 AM
If I fill in the blank cell on the left side of the table, how to modify it? Thanks.

YasserKhalil
04-17-2017, 11:44 AM
You're welcome
Try change this line


arr(i, j) = arr(1, j)
To

arr(i, j) = arr(i, 1)

idnoidno
04-17-2017, 10:12 PM
Thank you very much. I have found this little correction.

YasserKhalil
04-18-2017, 06:30 AM
You're welcome. Glad I can offer some help

idnoidno
04-18-2017, 06:53 AM
Hi,I would like to ask for no excel vba professional background of the people, to learn vba, what kind of advice you will give?

YasserKhalil
04-18-2017, 10:55 AM
Try to read books for beginners so as to be able to follow. You can watch Youtube channels such as WiseOwl Channel and other channels
And the most important is to try to apply what you learn and follow the forums too

idnoidno
04-19-2017, 05:49 AM
May I ask you a question?
myarr=Range("a3", Range("a2").End(xlDown).End(xlToRight))
IF a3 is replaced by a2,what is the difference?

YasserKhalil
04-19-2017, 05:05 PM
I think there is no difference .. but if you intend to store that range in array, you would put at the end .Value

idnoidno
04-19-2017, 06:07 PM
Excuse me, May I ask that what are the occasions to use this syntax of xlToRight and xltoLeft?

YasserKhalil
04-20-2017, 01:20 AM
In normal direction of columns A, B , C and so on you use XlToRight ... and if the vice versa you use XlToLeft
Try recording Ctrl + right arrow & Ctrl + Left arrow