issue with excel macro

kerm007

Active Member
Joined
Mar 16, 2019
Messages
250
Office Version
  1. 365
Platform
  1. Windows
hello in our compagny we have an excel that [roce a word document plus entry in the outlook
some one came to me cause they enter line 250 it steems to not filling all line
here the macro : not sure why it's not working :(
VBA Code:
Sub Main()

  StartForm.Show
 
  Dim Name As String
  Dim OwordDocument As WordDocument
  Dim OoutlookEvents As OutlookEvents
  Dim Item As String
  Dim Items() As String
  Dim element As Variant
 
  Sheet1.Activate
 
  If ActiveSheet.Cells(StartForm.LineTextBox, 1).Text <> "" Then
 
      Name = ActiveSheet.Cells(StartForm.LineTextBox, 1).Text
     
      Set OwordDocument = New WordDocument
      Set OoutlookEvents = New OutlookEvents

      OwordDocument.InsertTitle (Name)
     
      For i = 2 To 255
     
        If ActiveSheet.Cells(StartForm.LineTextBox, i).Text <> "" And i <> 30 Then
       
          Item = ActiveSheet.Cells(3, i).Text + " " + _
            ActiveSheet.Cells(2, i).Text + " " + ActiveSheet.Cells(4, i).Text + " " + _
            ActiveSheet.Cells(StartForm.LineTextBox, i).Text + ActiveSheet.Cells(5, i).Text + " " + _
            ActiveSheet.Cells(6, i).Text + ActiveSheet.Cells(7, i).Text + _
             " ,all tests"
             
          OwordDocument.InsertItem (Item)
          OoutlookEvents.SetEvent (Item)
       
        End If
     
      Next
     
      If ActiveSheet.Cells(StartForm.LineTextBox, 30).Text <> "" Then
       
        Items = Split(ActiveSheet.Cells(StartForm.LineTextBox, 30).Text, Chr(10))
       
        OwordDocument.InsertRetests




           
        For Each element In Items

            OwordDocument.InsertItem (element)
            OoutlookEvents.SetEvent ("Retest: " + element)
       
        Next element
       
      End If
 
  End If
 
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
she enter line 273 and it seems not to product the result wanted
 
Upvote 0
hello
any one know why it seems to stop when they enter line 273 ?
is it something in the macro ?
it was created long time ago by some one that is no longer with us
Thanks
 
Upvote 0
ok after discussion with the department
its an exel they fill in and it create a word document when they run the macro the problem is not the line but a column evrything they enter after the Column IV is not moved to the word document
is it possible there a limitation of the number of column they can fill in ?
Thanks
 
Last edited:
Upvote 0
Is it possible for you to upload the workbook in question?
 
Upvote 0
Increase the 255 in this line

VBA Code:
For i = 2 To 255

255 is Column IV, currently you're using to Col. 265 (JE), but if this is growing or changing, you can always calculate it at runtime.

This snippet will calculate the last used column from the right, of row 2
VBA Code:
Dim LastCol As Integer
    With ActiveSheet
        LastCol = .Cells(2, .Columns.Count).End(xlToLeft).Column
    End With

Which you can then reference:

VBA Code:
For i = 2 To LastCol
 
Upvote 1
Solution
The snippet should be added fairly early on, after sheet1.activate, before the if statement.

Then replace
For i = 2 To 255
With
For i = 2 To LastCol
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,390
Members
448,957
Latest member
Hat4Life

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