Share via

Is there error on this visual basic code?

Anonymous
2024-11-19T15:55:54+00:00

Option Explicit

Private Sub CommandButton1_Click()

End Sub

Private Sub cmdCreateFile_Click()

    Dim ColumnToSkip As Integer

    Dim FileNumber As Integer

    Dim K As Integer

    Dim Limit As Integer

    Dim LastColumn As Integer

    Dim Marker As Integer

    Dim StartColumn As Integer

    Dim Y As Integer

    Dim DataBucket As String

    Dim Filename As String

    Dim RangeName As String

    Dim RawData As Range

    StartColumn = 5

    ColumnToSkip = 16

    Filename = Trim(Range("I4"))

    Set RawData = Range("A6").CurrentRegion

    Limit = RawData.Rows.Count

    LastColumn = RawData.Columns.Count

    FileNumber = FreeFile

    Open Filename For Output As FileNumber

    Close FileNumber

    Kill Filename

    FileNumber = FreeFile

    Open Filename For Output As FileNumber

    For K = 5 To Limit

        If Trim(RawData.Cells(K, 2)) <> "" And Trim(RawData.Cells(K, 3)) <> "" Then

          'Row has some data to export

           For Y = StartColumn To LastColumn

               If Y <> ColumnToSkip Then

               If Val(Trim(RawData.Cells(K, Y))) <> 0 Then mismatch

                     DataBucket = Trim(RawData.Cells(K, 2)) & "," & Trim(RawData.Cells(2, Y)) & "," & Trim(Str(Val(Trim(RawData.Cells(K, Y)))))

                     Print #FileNumber, DataBucket

                  End If

               End If

           Next Y

        End If

    Next K

    Close FileNumber

    'RawData.Select

End Sub

Microsoft 365 and Office | Excel | For education | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2024-11-19T16:57:31+00:00

    Thank you. It works now.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2024-11-19T16:52:11+00:00

    Sub or Function is not defined

    Was this answer helpful?

    0 comments No comments
  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. HansV 462.6K Reputation points
    2024-11-19T16:26:22+00:00

    Do you get an error when you click the button?

    If so: what does the error message say?

    Was this answer helpful?

    0 comments No comments