Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:04:31+00:00 2026-06-14T13:04:31+00:00

I met with some problem with Excel Macro. I am trying too copy values

  • 0

I met with some problem with Excel Macro.
I am trying too copy values from various cells of a worksheet into an array for use of comparing with other worksheet’s cell value later.

However, I am stuck at the array to store all the value I am trying to assign to it.

Below is the code piece I have done.

Sub singleEntry(suppRow As Integer)

Dim j As Integer
Dim myArray() As Variant
Dim a As Integer
Dim b As Integer
Dim c As Integer

Worksheets("Ind. Supp. Plan Time").Select
Cells(suppRow, "I").Select

For j = 9 To 13
    c = j - 8

ReDim myArray(5, 4) As Variant
myArray(c, 1) = c

'ReDim Preserve myArray(5, 4) As Variant
If Cells(suppRow, j).Value = "*" Then
    ReDim Preserve myArray(5, 4) As Variant
    'myArray(j - 8, 1) = j - 8
    myArray(j - 8, 2) = Cells(suppRow, "P").Value
    myArray(j - 8, 3) = Cells(suppRow, "Q").Value
    myArray(j - 8, 4) = Cells(suppRow, "R").Value
    MsgBox "array = {" & myArray(c - 1, 2) & "}"
Else
    ReDim Preserve myArray(5, 4) As Variant
    myArray(j - 8, 2) = "1"
    myArray(j - 8, 3) = "1"
    myArray(j - 8, 4) = "1"
    MsgBox "array(1,3) = {" & myArray(1, 3) & "}"
End If

Next j

ReDim Preserve myArray(5, 4) As Variant
'For a = 1 To 5
'    For b = 1 To 4
'        MsgBox "Array = {" & myArray(a, b) & "}"
'    Next b
'Next a

End Sub

I put in MsgBox to view the result of executing the code, I am sure the lines are executed as expected.
If I print the value of the array straight away after assign one value to it, the value printed is correct.
However, now I can’t solve this problem.

Hopefully anyone know this can give me a help.

Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:04:32+00:00Added an answer on June 14, 2026 at 1:04 pm

    Not sure why you can’t retrieve values. I tested this and it works.

    Sub singleEntry(suppRow As Integer)
        Dim arrStore(1 To 5, 1 To 4) As Variant, col As Integer, r As Integer, c As Integer
    
        Worksheets("Ind. Supp. Plan Time").Select
    
        For col = 9 To 13
            arrStore(col - 8, 1) = col - 8
            arrStore(col - 8, 2) = IIf(Cells(suppRow, col) = "*", Cells(suppRow, "P"), 1)
            arrStore(col - 8, 3) = IIf(Cells(suppRow, col) = "*", Cells(suppRow, "Q"), 1)
            arrStore(col - 8, 4) = IIf(Cells(suppRow, col) = "*", Cells(suppRow, "R"), 1)
        Next col
    
        For r = 1 To 5
            For c = 1 To 4
               Debug.Print arrStore(r, c)
            Next c
        Next r
    
    End Sub
    

    Points to note:

    • Given that you always fill the array there is no need to ReDim. It’s redundant (and expensive)
    • I’ve used the ternary IIF statement to tidy up the code i.e. if “*” then x else 1
    • I don’t think you need the variable c so I’ve removed it
    • I’ve added a simple loop at the end to print out the array (which works for me)

    Does this solve it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I met with a problem. At first some code from AppDelegate. - (void)HideMainNavigationBar{ navigCtrl.navigationBarHidden
here I am trying to call overloaded constructor after some condition has met in
I met a problem when trying @Singleton of Guice: import com.google.inject.Singleton; @Singleton public class
I met some basic problem in jquery, but I can't figure it out. Here
I met some problem (I have to use socks proxy but only http proxy
I met some compilation error but do not know what the problem is. The
I have run into a strange to me problem. For some reason multiple ||
I'm trying to call a JavaScript function through PHP and have met some problems.
I have met some problem with jQuery ajax() in Safari, so I created some
I want to make a PHP JSON data foreach, but I met some problem.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.