Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Fri Apr 26, 2019 5:27 am

Hi. I need to loop this from row 1 until the end of data in column B, because it only can read the first row in column A only. I'm stuck with the code. really sorry.

Code: Select all
Dim workbook As Workbook = New Workbook
        workbook.Version = ExcelVersion.Version2007
        workbook.LoadFromFile(("sample.xlsx"))
        Dim sheet As Worksheet = workbook.Worksheets(0)
        If sheet.Range("B1").Text.StartsWith("AI") Then
            sheet.Range("A1").Text = "January"
        ElseIf sheet.Range("B1").Text.StartsWith("A") Then
           sheet.Range("A1").Text = "February"
        ElseIf sheet.Range("B1").Text.StartsWith("B") Then
            sheet.Range("A1").Text = "March"
        ElseIf sheet.Range("B1").Text.StartsWith("OR") Then
            sheet.Range("A1").Text = "April"

        ElseIf sheet.Range("B1").Text.StartsWith("QT") Then
            sheet.Range("A1").Text = "May"
        ElseIf sheet.Range("B1").Text.StartsWith("C") Then
           sheet.Range("A1").Text = "June"
        ElseIf sheet.Range("B1").Text.StartsWith("Q") Then
            sheet.Range("A1").Text = "July"
        Else
            sheet.Range("A1").Text = "NOT EXIST"
        End If

sitizalekoh
 
Posts: 15
Joined: Thu Apr 04, 2019 2:29 am

Fri Apr 26, 2019 7:04 am

Hello,

Thank you for contacting.
Please refer to the following code snippet to loop data in column B from row 1 to the end. If there is any question, please provide your input file(sample.xlsx) as well as your desired output, then we will further look into it and guide you accordingly. You could send them to us via email(support@e-iceblue.com).
Code: Select all
.....
For Each cell As CellRange In sheet.Range(sheet.FirstRow, 2, sheet.LastRow, 2)
     If cell.Text.StartsWith("AI") = True Then
     ....
     End If
 Next cell
.....

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Fri Apr 26, 2019 8:13 am

sorry but it doest work :'(

sitizalekoh
 
Posts: 15
Joined: Thu Apr 04, 2019 2:29 am

Fri Apr 26, 2019 11:50 am

Hello,

Thank you for sharing file via email and I noticed that my further email reply has resolved your issue. If you have other questions, please do not hesitate to contact us.
Wish you all the best!

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.XLS

cron